package com.roden.study.java.time;

import org.junit.Test;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.YearMonth;
import java.time.ZoneId;
import java.util.Date;

/**
 * @Author luod
 * @create 2023/2/15 9:56
 */
public class YearMonthTest {
    @Test
    public void monthBetween(){
        LocalDate localDate =LocalDate.now();
        Date dayStart = Date.from(LocalDateTime.of(localDate, LocalTime.MIN).atZone(ZoneId.systemDefault()).toInstant());
        Date dayEnd = Date.from(LocalDateTime.of(localDate, LocalTime.of(23,59,59)).atZone(ZoneId.systemDefault()).toInstant());
        System.out.println(dayStart);
        System.out.println(dayEnd);
        
        YearMonth yearMonth =YearMonth.now().minusMonths(1);
        Date monthStart=Date.from(yearMonth.atDay(1).atStartOfDay(ZoneId.systemDefault()).toInstant());
        Date monthEnd=Date.from(yearMonth.atEndOfMonth().atTime(23,59,59).atZone(ZoneId.systemDefault()).toInstant());
        System.out.println(monthStart);
        System.out.println(monthEnd);
    }
}
